<?php

/**
 * This is the model class for table "photo".
 *
 * The followings are the available columns in table 'photo':
 * @property integer $id_photo
 * @property string $name
 * @property string $small
 * @property string $big
 * @property string $hide
 * @property string $width
 * @property string $height
 * @property integer $position
 * @property integer $id_catalog
 */
class Photo extends CActiveRecord
{
        // public $file;


 
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

  
    public function tableName()
    {
        return '{{photo}}';
    }




     public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('width, height, position, id_catalog', 'numerical', 'integerOnly'=>true),
            array('hide', 'length', 'max'=>4),
            array('name, small, big', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id_photo, name, small, big, hide, width, height, position, id_catalog', 'safe', 'on'=>'search'),
        );
    }




  
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
           'photocat' =>array(self::BELONGS_TO, 'Photocat', 'id_catalog'), 
        );
    }

   
    public function attributeLabels()
    {
        return array(
            'id_photo' => 'Категория',
            'name' => 'Название изображения',
            'small' => 'Миниатюра',
            'big' => 'Полноразмерное',
            'hide' => 'Статус',
            'width'=> 'Ширина изображения',
            'height'=>'Высота изображения (в приоритете*)',
            'position'=>'Позиция изображения',
            'id_catalog' => 'Id Catalog',
        );
    }

 /*   
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id_photo',$this->id_photo);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('small',$this->small,true);
        $criteria->compare('big',$this->big,true);
        $criteria->compare('hide',$this->hide,true);
        $criteria->compare('width',$this->width);
        $criteria->compare('height',$this->height);
        $criteria->compare('id_catalog',$this->id_catalog);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
   */ 

/*
     public static function allphotos($cat)   //Функция возвращает список фото
    {
      //  return CHtml::listData(self::model()->findAllByAttributes(array('id_catalog'=>$cat)), 'id_photo', $field);
        
        $arr = array();
        $arr = self::model()->findAllByAttributes(array('id_catalog'=>$cat));
        return $arr;
    }
*/

    public function beforeSave()
    {
        
         $this->position = DKUtils::maxposition("Photo") + 1;
        return parent::beforeSave();
    }


}  //  end class

?>